
#include "AC33Mxxx_conf.h"

#ifndef __UART_DRV_H__
#define __UART_DRV_H__

//==================================================================
// definitions
//==================================================================
#define UART_MAX_RX_BUFFER					(100)
#define UART_MAX_TX_BUFFER					(100)

#define UART_CHANNEL_SUPPORTED				(1)
#define UART_CHANNEL_NOT_SUPPORTED			(0)




//------------------------------------------------------------------------------------
// definitions for TX/RX state  
//------------------------------------------------------------------------------------
#define UART_RX_STATE_IDLE					(0)
#define UART_RX_STATE_RECEIVE				(1)


#define UART_TX_STATE_IDLE					(0)
#define UART_TX_STATE_TRANSMIT				(1)


//------------------------------------------------------------------------------------
// definitions for read/write function 
//------------------------------------------------------------------------------------
#define UART_TX_BUFFER_SUCCESS				(0)
#define UART_TX_BUFFER_ERROR_WRONG_CHANNEL	(1)
#define UART_TX_BUFFER_ERROR_WAIT_TIMEOUT	(2)

#define UART_RX_BUFFER_SUCCESS				(0)
#define UART_RX_BUFFER_ERROR_WRONG_CHANNEL	(1)
#define UART_RX_BUFFER_ERROR_EMPTY			(2)


//------------------------------------------------------------------------------------
// definitions for UART interrupts
//------------------------------------------------------------------------------------
#define UART_INTR_RX						(UnIER_DRIE)
#define UART_INTR_TX						(UnIER_THREIE)
#define UART_INTR_LINE						(UnIER_RLSIE)





//==================================================================
// structures
//==================================================================
typedef struct {
	volatile UINT16		u16RxState; 
	volatile UINT16		u16TxState; 
	volatile UINT16		u16RxBuffer_HeadIndex;
	volatile UINT16 	u16RxBuffer_TailIndex;
	volatile UINT16		u16TxBuffer_HeadIndex;
	volatile UINT16 	u16TxBuffer_TailIndex;
	volatile UINT8		u8RxBuffer[UART_MAX_RX_BUFFER];
	volatile UINT8		u8TxBuffer[UART_MAX_TX_BUFFER]; 
} UART_BUFFER; 



//==================================================================
// export variables
//==================================================================
extern UART_BUFFER		sUart0Buffer; 
extern UART_BUFFER		sUart1Buffer; 
extern UART_BUFFER		sUart2Buffer; 
extern UART_BUFFER		sUart3Buffer; 
extern UART_BUFFER		sUart4Buffer; 
extern UART_BUFFER		sUart5Buffer; 




//==================================================================
// function declaration
//==================================================================
void UART_Init (int uart_no,int bps); 

CSP_UART_T* UART_Get_Object (int uart_no); 
void UART_InitBuffer (int uart_no); 
UART_BUFFER* UART_GetBufferBaseAddr (int uart_no, int *pResult); 

UINT8 UART_WriteBuffer (int uart_no, UINT8 *p_data, UINT32 data_count); 
void UART_Enable_TX_Interrupt (int uart_no, int enable); 
int UART_GetChar (int uart_no); 
UINT8 UART_ReadBuffer (int uart_no, int *p_status); 
///////////////////////////////////////////////////////////////////////////////

void UART0_Transmit_Receive_ISR(void); 
void UART0_ReceiveData_ISR (void); 
void UART0_TransmitData_ISR (void); 

#if 0
void UART1_Transmit_Receive_ISR(void); 
void UART1_ReceiveData_ISR (void); 
void UART1_TransmitData_ISR (void); 

void UART2_Transmit_Receive_ISR(void); 
void UART2_ReceiveData_ISR (void); 
void UART2_TransmitData_ISR (void); 

void UART3_Transmit_Receive_ISR(void); 
void UART3_ReceiveData_ISR (void); 
void UART3_TransmitData_ISR (void); 

#endif






#endif 

